﻿package uiresource.map
{
    import flash.events.*;
    import morn.core.components.*;

    public class LabelWithImageUI extends View
    {
        private var _func:Function;
        private var _overfunc:Function;
        public var img:UrlImage;
        public var text:Label;
        public var data:Object = null;

        public function LabelWithImageUI(param1:Function = null, param2:Function = null)
        {
            this._func = param1;
            this._overfunc = param2;
            return;
        }// end function

        override protected function createChildren() : void
        {
            loadUI("LabelWithImage.xml");
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            this.img.addEventListener(MouseEvent.ROLL_OVER, this.rollOverHandler);
            this.img.addEventListener(MouseEvent.ROLL_OUT, this.rollOutHandler);
            this.img.addEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            event.stopPropagation();
            if (this._func != null)
            {
                this._func(this.data);
            }
            return;
        }// end function

        protected function rollOutHandler(event:MouseEvent) : void
        {
            this.doover(1);
            return;
        }// end function

        protected function rollOverHandler(event:MouseEvent) : void
        {
            this.doover(0);
            return;
        }// end function

        private function doover(param1:int) : void
        {
            if (this._overfunc != null)
            {
                this._overfunc(param1, this.data);
            }
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function setpivotXY(param1:int, param2:int) : void
        {
            this.x = param1 - this.img.x - this.img.width / 2;
            this.y = param2 - this.img.y - this.img.height / 2;
            return;
        }// end function

    }
}
